//
//  PicDetailViewController.m
//  MansApp
//
//  Created by lanou3g on 15/7/22.
//  Copyright (c) 2015年 ACH. All rights reserved.
//

#import "PicDetailViewController.h"
#import "PicTableViewCell.h"
#import "PicModel.h"
@interface PicDetailViewController ()<UITableViewDataSource,UITableViewDelegate,UMSocialUIDelegate>
@property (nonatomic,strong) UITableView *tabalView;
@property (nonatomic,strong) NSMutableArray *modelArray;
@end

@implementation PicDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
   
    self.tabalView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight) style:UITableViewStylePlain];
    self.tabalView.delegate = self;
    self.tabalView.dataSource = self;
    self.tabalView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview: _tabalView];
    [self.tabalView registerClass:[PicTableViewCell class] forCellReuseIdentifier:@"detailClass"];
    [self fuzhiModel];
}
- (NSMutableArray *)modelArray
{
    if (!_modelArray)
    {
        _modelArray = [[NSMutableArray alloc]init];
    }
    return _modelArray;
}
//给model赋值
- (void)fuzhiModel
{
    PicModel *model = [[PicModel alloc]init];
    model.detail_url = _raw_url;
    model.title = _titleText;
    [self.modelArray addObject:model];
    [self.tabalView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detailClass" forIndexPath:indexPath];
    PicModel *model = _modelArray[indexPath.row];
    [cell cellSetDetailModel:model];
    [cell.goodButton addTarget:self action:@selector(goodButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell.shareButton addTarget:self action:@selector(shareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)goodButtonAction:(UIButton *)but
{
    but.userInteractionEnabled = NO;
    [MBProgressHUD showError:@"+1"];
    [but setBackgroundImage:[UIImage imageNamed:@"Thumb-orange-16@2x.png"] forState:UIControlStateNormal];
}
- (void)shareButtonAction:(UIButton *)button
{
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"55a87dbd67e58eb9b30039ad"
                                      shareText:self.weburl
                                     shareImage:nil
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToDouban,UMShareToQQ,UMShareToQzone,UMShareToWechatTimeline,nil]delegate:self];
    button.userInteractionEnabled = NO;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PicTableViewCell *cell = [[PicTableViewCell alloc]init];
    PicModel *model = [self.modelArray objectAtIndex:indexPath.row];
    return [cell heightForDetail:model] + kP6Height(44);
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [[SDImageCache sharedImageCache] clearMemory];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    [[SDImageCache sharedImageCache] clearMemory];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
